using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace SurveyHost.Core.DAL
{
	/// <summary>
	/// Strongly-typed collection for the UserStatus class.
	/// </summary>
	[Serializable]
	public partial class UserStatusCollection : ActiveList<UserStatus, UserStatusCollection> 
	{	   
		public UserStatusCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the UserStatus table.
	/// </summary>
	[Serializable]
	public partial class UserStatus : ActiveRecord<UserStatus>
	{
		#region .ctors and Default Settings
		
		public UserStatus()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public UserStatus(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public UserStatus(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public UserStatus(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("UserStatus", TableType.Table, DataService.GetInstance("SurveyHost"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarUserId = new TableSchema.TableColumn(schema);
				colvarUserId.ColumnName = "UserId";
				colvarUserId.DataType = DbType.Guid;
				colvarUserId.MaxLength = 0;
				colvarUserId.AutoIncrement = false;
				colvarUserId.IsNullable = false;
				colvarUserId.IsPrimaryKey = true;
				colvarUserId.IsForeignKey = true;
				colvarUserId.IsReadOnly = false;
				colvarUserId.DefaultSetting = @"";
				
					colvarUserId.ForeignKeyTableName = "aspnet_Users";
				schema.Columns.Add(colvarUserId);
				
				TableSchema.TableColumn colvarEnteredName = new TableSchema.TableColumn(schema);
				colvarEnteredName.ColumnName = "EnteredName";
				colvarEnteredName.DataType = DbType.String;
				colvarEnteredName.MaxLength = 100;
				colvarEnteredName.AutoIncrement = false;
				colvarEnteredName.IsNullable = false;
				colvarEnteredName.IsPrimaryKey = false;
				colvarEnteredName.IsForeignKey = false;
				colvarEnteredName.IsReadOnly = false;
				colvarEnteredName.DefaultSetting = @"";
				colvarEnteredName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEnteredName);
				
				TableSchema.TableColumn colvarConsentDate = new TableSchema.TableColumn(schema);
				colvarConsentDate.ColumnName = "ConsentDate";
				colvarConsentDate.DataType = DbType.DateTime;
				colvarConsentDate.MaxLength = 0;
				colvarConsentDate.AutoIncrement = false;
				colvarConsentDate.IsNullable = false;
				colvarConsentDate.IsPrimaryKey = false;
				colvarConsentDate.IsForeignKey = false;
				colvarConsentDate.IsReadOnly = false;
				
						colvarConsentDate.DefaultSetting = @"(getdate())";
				colvarConsentDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarConsentDate);
				
				TableSchema.TableColumn colvarCompleted = new TableSchema.TableColumn(schema);
				colvarCompleted.ColumnName = "Completed";
				colvarCompleted.DataType = DbType.Boolean;
				colvarCompleted.MaxLength = 0;
				colvarCompleted.AutoIncrement = false;
				colvarCompleted.IsNullable = false;
				colvarCompleted.IsPrimaryKey = false;
				colvarCompleted.IsForeignKey = false;
				colvarCompleted.IsReadOnly = false;
				
						colvarCompleted.DefaultSetting = @"((0))";
				colvarCompleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompleted);
				
				TableSchema.TableColumn colvarAreOrOver18 = new TableSchema.TableColumn(schema);
				colvarAreOrOver18.ColumnName = "AreOrOver18";
				colvarAreOrOver18.DataType = DbType.Boolean;
				colvarAreOrOver18.MaxLength = 0;
				colvarAreOrOver18.AutoIncrement = false;
				colvarAreOrOver18.IsNullable = false;
				colvarAreOrOver18.IsPrimaryKey = false;
				colvarAreOrOver18.IsForeignKey = false;
				colvarAreOrOver18.IsReadOnly = false;
				
						colvarAreOrOver18.DefaultSetting = @"((0))";
				colvarAreOrOver18.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAreOrOver18);
				
				TableSchema.TableColumn colvarRelationshipInPastYear = new TableSchema.TableColumn(schema);
				colvarRelationshipInPastYear.ColumnName = "RelationshipInPastYear";
				colvarRelationshipInPastYear.DataType = DbType.Boolean;
				colvarRelationshipInPastYear.MaxLength = 0;
				colvarRelationshipInPastYear.AutoIncrement = false;
				colvarRelationshipInPastYear.IsNullable = false;
				colvarRelationshipInPastYear.IsPrimaryKey = false;
				colvarRelationshipInPastYear.IsForeignKey = false;
				colvarRelationshipInPastYear.IsReadOnly = false;
				
						colvarRelationshipInPastYear.DefaultSetting = @"((0))";
				colvarRelationshipInPastYear.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRelationshipInPastYear);
				
				TableSchema.TableColumn colvarValidationComplete = new TableSchema.TableColumn(schema);
				colvarValidationComplete.ColumnName = "ValidationComplete";
				colvarValidationComplete.DataType = DbType.Boolean;
				colvarValidationComplete.MaxLength = 0;
				colvarValidationComplete.AutoIncrement = false;
				colvarValidationComplete.IsNullable = false;
				colvarValidationComplete.IsPrimaryKey = false;
				colvarValidationComplete.IsForeignKey = false;
				colvarValidationComplete.IsReadOnly = false;
				
						colvarValidationComplete.DefaultSetting = @"((0))";
				colvarValidationComplete.ForeignKeyTableName = "";
				schema.Columns.Add(colvarValidationComplete);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["SurveyHost"].AddSchema("UserStatus",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("UserId")]
		public Guid UserId 
		{
			get { return GetColumnValue<Guid>("UserId"); }

			set { SetColumnValue("UserId", value); }

		}

		  
		[XmlAttribute("EnteredName")]
		public string EnteredName 
		{
			get { return GetColumnValue<string>("EnteredName"); }

			set { SetColumnValue("EnteredName", value); }

		}

		  
		[XmlAttribute("ConsentDate")]
		public DateTime ConsentDate 
		{
			get { return GetColumnValue<DateTime>("ConsentDate"); }

			set { SetColumnValue("ConsentDate", value); }

		}

		  
		[XmlAttribute("Completed")]
		public bool Completed 
		{
			get { return GetColumnValue<bool>("Completed"); }

			set { SetColumnValue("Completed", value); }

		}

		  
		[XmlAttribute("AreOrOver18")]
		public bool AreOrOver18 
		{
			get { return GetColumnValue<bool>("AreOrOver18"); }

			set { SetColumnValue("AreOrOver18", value); }

		}

		  
		[XmlAttribute("RelationshipInPastYear")]
		public bool RelationshipInPastYear 
		{
			get { return GetColumnValue<bool>("RelationshipInPastYear"); }

			set { SetColumnValue("RelationshipInPastYear", value); }

		}

		  
		[XmlAttribute("ValidationComplete")]
		public bool ValidationComplete 
		{
			get { return GetColumnValue<bool>("ValidationComplete"); }

			set { SetColumnValue("ValidationComplete", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varUserId,string varEnteredName,DateTime varConsentDate,bool varCompleted,bool varAreOrOver18,bool varRelationshipInPastYear,bool varValidationComplete)
		{
			UserStatus item = new UserStatus();
			
			item.UserId = varUserId;
			
			item.EnteredName = varEnteredName;
			
			item.ConsentDate = varConsentDate;
			
			item.Completed = varCompleted;
			
			item.AreOrOver18 = varAreOrOver18;
			
			item.RelationshipInPastYear = varRelationshipInPastYear;
			
			item.ValidationComplete = varValidationComplete;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varUserId,string varEnteredName,DateTime varConsentDate,bool varCompleted,bool varAreOrOver18,bool varRelationshipInPastYear,bool varValidationComplete)
		{
			UserStatus item = new UserStatus();
			
				item.UserId = varUserId;
				
				item.EnteredName = varEnteredName;
				
				item.ConsentDate = varConsentDate;
				
				item.Completed = varCompleted;
				
				item.AreOrOver18 = varAreOrOver18;
				
				item.RelationshipInPastYear = varRelationshipInPastYear;
				
				item.ValidationComplete = varValidationComplete;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string UserId = @"UserId";
			 public static string EnteredName = @"EnteredName";
			 public static string ConsentDate = @"ConsentDate";
			 public static string Completed = @"Completed";
			 public static string AreOrOver18 = @"AreOrOver18";
			 public static string RelationshipInPastYear = @"RelationshipInPastYear";
			 public static string ValidationComplete = @"ValidationComplete";
						
		}

		#endregion
	}

}

